package com.tool.engine.export.factory.thread;

import com.tool.engine.config.ExportTaskProperties;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ExportTaskThreadPoolFactory {

    public static ExecutorService createExecutorService(ExportTaskProperties exportTaskProperties) {
        return new ThreadPoolExecutor(
                exportTaskProperties.getCorePoolSize(),
                exportTaskProperties.getMaxPoolSize(),
                exportTaskProperties.getKeepAliveSeconds(),
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(exportTaskProperties.getQueueCapacity()),
                new ExportTaskThreadFactory("export-task-thread-"),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

}
